<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<p> 공급자 등록양식</p>
<form id="form1" name="form1" method="post" action="">
	<fieldset>
		<table summary="공급자양식">
			<tbody>
				<tr>
					<th scope="row" align="left">
						 코드
					</th>
					<td>
						<c:if test="${provider eq null }">
							<input type="text" id="code" name="code" value="" />
						</c:if>
						<c:if test="${provider ne null }">
							<input type="hidden" id="code" name="code" value="${provider.code}" />${provider.code }
						</c:if>
					</td>
				</tr>
				<tr>
					<th scope="row" align="left">이름</th>
					<td>
						<input type="text" id="name" name="name" value="${provider.name }" />
					</td>				
				</tr>
				<tr>
					<th scope="row" align="left">
						홈페이지
					</th>
					<td>
						<input type="text" name="homepage" id="homepage" value="${provider.homepage }"/>
					</td>				
				</tr>
				<tr>
					<th scope="row" align="left">
						전화번호
					</th>
					<td>
						<input type="text" name="telephone" id="telephone" value="${provider.telephone }"/>
					</td>				
				</tr>
				<tr>
					<th scope="row" align="left">
						 이메일
					</th>
					<td>
						<input type="text" name="email" id="email" value="${provider.email }"/>
					</td>				
				</tr>
				<tr>
					<td>
					</td>
				</tr>
			</tbody>
		</table>
	</fieldset>
</form> 
	<div>
		<c:if test="${provider eq null }">
		<button onclick="registe();" style="font-size:12px;font-family: Malgun Gothic,Gulim;padding:0;margin:0">확인</button>
		</c:if>
		<c:if test="${provider ne null }">
		<button onclick="update();" style="font-size:12px;font-family: Malgun Gothic,Gulim;padding:0;margin:0">수정</button>
		</c:if>
		<button onclick="goList();" style="font-size:12px;font-family: Malgun Gothic,Gulim;padding:0;margin:0">목록</button>
	</div>	
<script type="text/javascript">
	var form1 = document.form1;		
	
	var registe = function(){
		var a = checkAll();
		if(a == true){
			form1.action ="/admin/provider/registe.html"
			form1.submit();
		}
	}
	
	var update = function(){
		var a = checkAll();
		if(a == true){
			form1.action ="/admin/provider/modify.html"
			form1.submit();
		}
	}
	
	var goList = function(){
			location.href = "/admin/provider/list.html"; 
			location.replace("/admin/provider/list.html"); 
	}
	
	var checkAll = function(){
		
		if(form1.code.value == null || form1.code.value == ''){ 
			alert("코드를 입력하세요"); 
			return false;
		}
		else if(form1.name.value == null || form1.name.value == ''){ 
			alert("이름을 입력하세요"); 
			return false;
		}
		else if(form1.homepage.value == null || form1.homepage.value == ''){
			alert("홈페이지를 입력하세요"); 
			return false;
		}
		else if(form1.telephone.value == null || form1.telephone.value == ''){
			 alert("전화번호를 입력하세요"); 
			 return false;
		}
		else if(form1.email.value == null || form1.email.value == ''){
			alert("이메일을 입력하세요"); 
			return false;
		}
		else return true;
		
	}
</script>
